home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / SERIAL5.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  4KB  |  146 lines

  1. ;************************************;
  2. ; WASM Serial I/O, Timed Input       ;
  3. ; By Eric Tauck                      ;
  4. ;                                    ;
  5. ; Defines:                           ;
  6. ;                                    ;
  7. ;   ComWai   wait for a byte of data ;
  8. ;   ComWaiW  wait for a word of data ;
  9. ;   ComAny   wait for any data       ;
  10. ;                                    ;
  11. ; Requires:                          ;
  12. ;                                    ;
  13. ;   SERIAL1.ASM                      ;
  14. ;   SERIAL2.ASM                      ;
  15. ;   TICKS.ASM                        ;
  16. ;************************************;
  17.  
  18.         jmps    _serial5_end
  19.  
  20. ;========================================
  21. ; Wait for and read a byte.
  22. ;
  23. ; In: BX= record address; AX= timeout
  24. ;     ticks.
  25. ;
  26. ; Out: AL= byte; CY= set if timeout.
  27.  
  28. ComWai  PROC    NEAR
  29.         push    di
  30.         push    si
  31.         mov     di, bx          ;save record address
  32.         mov     si, ax          ;save timeout value
  33.  
  34.         sub     al, al          ;timer zero
  35.         call    TicRes          ;reset timer
  36.  
  37. _cmwai1 mov     bx, di
  38.         call    ComGet          ;get byte
  39.         jnc     _cmwai2         ;jump if byte returned
  40.  
  41.         sub     al, al          ;timer zero
  42.         call    TicPas          ;get time passed
  43.         cmp     ax, si          ;check if timeout
  44.         jb      _cmwai1         ;loop back if not
  45.  
  46. ;--- finished, timeout
  47.  
  48.         pop     si
  49.         pop     di
  50.         stc
  51.         ret
  52.  
  53. ;--- finished, no timeout
  54.  
  55. _cmwai2 pop     si
  56.         pop     di
  57.         clc
  58.         ret
  59.         ENDP
  60.  
  61. ;========================================
  62. ; Wait for and read a word.
  63. ;
  64. ; In: BX= record address; AX= timeout
  65. ;     ticks.
  66. ;
  67. ; Out: AX= word; CY= set if timeout.
  68.  
  69. ComWaiW PROC    NEAR
  70.         push    di
  71.         push    si
  72.         mov     di, bx          ;save record address
  73.         mov     si, ax          ;save timeout value
  74.  
  75.         sub     al, al          ;timer zero
  76.         call    TicRes          ;reset timer
  77.  
  78. _cmwaw1 mov     bx, di
  79.         call    ComGetW         ;get byte
  80.         jnc     _cmwaw2         ;jump if byte returned
  81.  
  82.         sub     al, al          ;timer zero
  83.         call    TicPas          ;get time passed
  84.         cmp     ax, si          ;check if timeout
  85.         jb      _cmwaw1         ;loop back if not
  86.  
  87. ;--- finished, timeout
  88.  
  89.         pop     si
  90.         pop     di
  91.         stc
  92.         ret
  93.  
  94. ;--- finished, no timeout
  95.  
  96. _cmwaw2 pop     si
  97.         pop     di
  98.         clc
  99.         ret
  100.         ENDP
  101.  
  102. ;========================================
  103. ; Wait for any data.  The data is not
  104. ; read.
  105. ;
  106. ; In: BX= record address; AX= timeout
  107. ;     ticks.
  108. ;
  109. ; Out: CY= set if timeout.
  110.  
  111. ComAny  PROC    NEAR
  112.         push    di
  113.         push    si
  114.         mov     di, bx          ;save record address
  115.         mov     si, ax          ;save timeout value
  116.  
  117.         sub     al, al          ;timer zero
  118.         call    TicRes          ;reset timer
  119.  
  120. _cmwaa1 mov     bx, di
  121.         call    ComByt          ;get bytes in buffer
  122.         or      ax, ax          ;check if any bytes
  123.         jnz     _cmwaa2         ;jump if so
  124.  
  125.         sub     al, al          ;timer zero
  126.         call    TicPas          ;get time passed
  127.         cmp     ax, si          ;check if timeout
  128.         jb      _cmwaa1         ;loop back if not
  129.  
  130. ;--- finished, timeout
  131.  
  132.         pop     si
  133.         pop     di
  134.         stc
  135.         ret
  136.  
  137. ;--- finished, no timeout
  138.  
  139. _cmwaa2 pop     si
  140.         pop     di
  141.         clc
  142.         ret
  143.         ENDP
  144.  
  145. _serial5_end
  146.